package cn.byapps.attendance.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.byapps.attendance.dao.CompanyDao;
import cn.byapps.attendance.entity.Company;
import cn.byapps.attendance.service.CompanyService;
import cn.byapps.attendance.util.DataTablesResult;
import core.service.impl.BaseServiceImpl;

@Service
public class CompanyServiceImpl extends BaseServiceImpl<Company> implements CompanyService {

	@Resource
	private CompanyDao companyDao;

	@Override
	public List<Company> listAll() {
		Map<String, Object> maps = new HashMap<String, Object>();
		maps.put("flag",true);
		return companyDao.findAll(maps);
	}

	@Override
	public DataTablesResult<Company> getData(Integer draw,Integer pos,Integer rows) {
		DataTablesResult<Company> ads = new DataTablesResult<Company>();
		ads.setDraw(draw);
		ads.setData(companyDao.find(pos, rows));
		long total = companyDao.count();
		ads.setRecordsFiltered(total);
		ads.setRecordsTotal(total);
		return ads;
	}

	@Override
	public Company updateName(Company entity) {
		Company ad  = companyDao.get(entity.getId());
		ad.setName(entity.getName());
		return ad;
	}

	@Override
	public Company updateFlag(Integer id) {
		Company ad  = companyDao.get(id);
		ad.setFlag(!ad.getFlag());
		return ad;
	}

}
